import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:ilab_service_app2/widgets/loading_dialog.dart';
import '/modules/banner/banner.dart';
import '/base/view.dart';
import '/Routes.dart';
import 'logic.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class HomePage extends StatelessWidget {
  final logic = Get.put(HomeLogic());
  final state = Get
      .find<HomeLogic>()
      .state;

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      decoration: const BoxDecoration(
          image: DecorationImage(
              fit: BoxFit.cover, image: AssetImage("images/home/bg.png"))),
      child: ListView(
        children: [
          SizedBox(
            height: 10.w,
          ),
          Center(
              child: Text(
                "home".tr,
                style: TextStyle(
                    color: const Color(0xFF333333), fontSize: 18.w),
              )),
          SizedBox(
            height: 51.w,
          ),
          SizedBox(
            height: 24.h,
          ),
          GestureDetector(
            child: getListViewItem("images/home/list_item1.png"),
            onTap: () {
              Get.toNamed(Routes.routePhoto);
            },
          ),
          SizedBox(
            height: 24.w,
          ),
          GestureDetector(
            child: getListViewItem("images/home/list_item2.png"),
            onTap: () {
              Get.toNamed(Routes.routeInventory);
            },
          ),
          SizedBox(
            height: 24.w,
          ),
          GestureDetector(
            child: getListViewItem("images/home/list_item3.png"),
            onTap: () {
              logic.saveSp();
              Get.toNamed(Routes.routeInventory);
            },
          ),
          const ExampleHorizontal(),
          ElevatedButton(
            onPressed: () {
              Get.toNamed(Routes.routePhoto);
            },
            child: const Text("相片"),
          ),
          ElevatedButton(
            onPressed: () {
              Get.toNamed(Routes.routeDrawer);
            },
            child: const Text("抽屉"),
          ),
          ElevatedButton(
            onPressed: () {
              Get.toNamed(Routes.routeSleek);
            },
            child: const Text("滑动进度条"),
          ),
          ElevatedButton(
            onPressed: () {
              Get.toNamed(Routes.routeNet);
            },
            child: const Text("网络请求"),
          ),
          ElevatedButton(
            onPressed: () {
              SmartDialog.show(widget: LoadingDialog("x..."));
              SmartDialog.show(widget: LoadingDialog("x333..."));
              SmartDialog.show(widget: LoadingDialog("x444..."));
              // SmartDialog.showLoading(msg: "xxxxxxxxxxx${0}");
              // for (int i = 0; i < 5; i++) {
              //   Future.delayed(Duration(seconds: 3)).then((value) =>
              //   {
              //     SmartDialog.showLoading(msg: "xxxxxxxxxxx${i}")
              //   });
              // }
            },
            child: const Text("测试网络加载弹框"),
          ),
        ],
      ),
    );
  }

  /**
   * 单个列表条目
   */
  Widget getListViewItem(String url) {
    return Container(
      width: double.infinity,
      height: 120.w,
      margin: EdgeInsets.symmetric(horizontal: 16.w),
      decoration: BoxDecoration(
          image: DecorationImage(fit: BoxFit.cover, image: AssetImage(url)),
          borderRadius: BorderRadius.circular(8.w)),
    );
  }
}
